(function() {
    window.TED = window.TED || {};
    window.TED["extend"] = extend;
    window.TED["EventDispatcher"] = EventDispatcher;
    function extend(M, N, I) {
        function K() {
        }
        K.prototype = N.prototype;
        var L = new K();
        L.constructor = M;
        M.superclass = N;
        for (var J in I) {
            L[J] = I[J]
        }
        M.prototype = L
    }
    function EventDispatcher() {
        this._events = {}
    }
    EventDispatcher.prototype = {on: function(K, L, J, I) {
            J = J || this;
            this._events[K] = this._events[K] || [];
            this._events[K].push({listener: L,scope: J,args: I})
        },fireEvent: function(N, M, J) {
            var O, L, I, K = this._events[N];
            if (!K) {
                return false
            } else {
                for (L = 0, I = K.length; L < I; L++) {
                    O = K[L];
                    M = O.scope;
                    J = J || O.args || [];
                    O.listener.apply(M, J)
                }
            }
        },remove: function(L, M) {
            if (!this._events[L]) {
                return false
            }
            var K = this._events[L], J, I;
            for (J = 0, I = K.length; J < I; J++) {
                if (K[J].listener === M) {
                    K.splice(J, 1);
                    break
                }
            }
            if (K.length === 0) {
                delete this._events[L]
            }
        }};
    var Event = {addEvent: function(J, I, K) {
            var L;
            if (J.addEventListener) {
                L = function(N, M, O) {
                    N.addEventListener(M, O, false)
                }
            } else {
                L = function(N, M, O) {
                    N.attachEvent("on" + M, O)
                }
            }
            L(J, I, K);
            this.addEvent = L
        },removeEvent: function(K, J, L) {
            var I;
            if (K.addEventListener) {
                I = function(N, M, O) {
                    N.removeEventListener(M, linstener, false)
                }
            } else {
                I = function(N, M, O) {
                    N.detachEvent("on" + M, O)
                }
            }
            I(K, J, L);
            this.addEvent = I
        }};
    window.TED["Event"] = Event;
    window.TED["HoverOverlay"] = HoverOverlay;
    function HoverOverlay(I) {
        HoverOverlay.superclass.call(this);
        this.timer = null;
        this.container = I;
        this.holder = document.createElement("div");
        this.holder.className = "tb-editor-overlay";
        this.holder.style.display = "none";
        var J = this;
        Event.addEvent(this.holder, "mouseover", function() {
            J.mouseover()
        });
        Event.addEvent(this.holder, "mouseout", function() {
            J.mouseout()
        });
        this.content = document.createElement("div");
        this.content.className = "overlay-content";
        this.arrow = document.createElement("span");
        this.arrow.className = "arrow";
        this.holder.appendChild(this.arrow);
        this.holder.appendChild(this.content);
        this.container.appendChild(this.holder)
    }
    extend(HoverOverlay, EventDispatcher, {container: null,holder: null,content: null,currentOpen: null,isOpen: false,closefunction: null,open: function(O, N, M, I, P, J, L) {
            this.isOpen = true;
            this.currentOpen = L;
            this.arrow.style.left = P;
            var K = this.holder.style;
            K.left = O;
            K.top = N;
            K.width = M;
            K.height = I;
            K.display = "block";
            this.content.innerHTML = '<iframe width="100%" height="100%" frameborder="0" scrolling="no" src="' + J + '"></iframe>'
        },close: function() {
            this.isOpen = false;
            this.content.innerHTML = "";
            this.holder.style.display = "none";
            if (this.currentOpen) {
                this.currentOpen.className = this.currentOpen.className.replace(" open", "");
                this.currentOpen = null
            }
            this.fireEvent("close")
        },mouseover: function() {
            this.closefunction = this.close;
            this.close = function() {
            };
            if (this.timer != null) {
                clearTimeout(this.timer)
            }
        },mouseout: function() {
            var I = this;
            I.close = I.closefunction;
            I.timer = setTimeout(function() {
                I.close()
            }, 500)
        }});
    window.TED["Overlay"] = Overlay;
    function Overlay(I) {
        Overlay.superclass.call(this);
        this.container = I;
        this.holder = document.createElement("div");
        this.holder.className = "tb-editor-overlay";
        this.holder.style.display = "none";
        this.closeBtn = document.createElement("span");
        this.closeBtn.className = "close";
        var J = this;
        Event.addEvent(this.closeBtn, "click", function() {
            J.close()
        });
        this.content = document.createElement("div");
        this.content.className = "overlay-content";
        this.arrow = document.createElement("span");
        this.arrow.className = "arrow";
        this.holder.appendChild(this.closeBtn);
        this.holder.appendChild(this.arrow);
        this.holder.appendChild(this.content);
        this.container.appendChild(this.holder)
    }
    extend(Overlay, EventDispatcher, {closeButton: null,container: null,holder: null,content: null,currentOpen: null,isOpen: false,open: function(L, P, K, Q, M, J) {
            if (this.isOpen == true && TED.Editor.Status.isPicassoOpen === true) {
                var N = this;
                var O = $.dialog.confirm('<div id="maincontent" style="position:absolute;"><img style="margin:10px 10px 10px 10px;width:68px;height:68px;" src="http://static.tieba.baidu.com/tb/editor/v2/picasso/alarm.gif" /><div id="tipscontent" style="position:absolute;left:100px;top:15px;width:270px;font-size:14px;font-family:宋体" ><b>您正在编辑涂鸦，现在退出将不会保存，您确定要退出？</b></div></div>', {title: "涂鸦编辑器",acceptValue: "确定",cancelValue: "取消"});
                O.width(420);
                O.height(90);
                O.bind("onaccept", function() {
                    TED.Editor.Status.isPicassoOpen = false;
                    N.isOpen = true;
                    N.arrow.style.left = M;
                    var R = N.holder.style;
                    R.left = L;
                    R.top = P;
                    R.width = K;
                    R.height = Q;
                    R.display = "block";
                    N.content.innerHTML = '<iframe width="100%" height="100%" frameborder="0" scrolling="no" src="' + J + '"></iframe>'
                })
            } else {
                this.isOpen = true;
                this.arrow.style.left = M;
                var I = this.holder.style;
                I.left = L;
                I.top = P;
                I.width = K;
                I.height = Q;
                I.display = "block";
                this.content.innerHTML = '<iframe width="100%" height="100%" frameborder="0" scrolling="no" src="' + J + '"></iframe>'
            }
            this.fireEvent("open")
        },close: function(J) {
            if (TED.Editor.Status.isPicassoOpen === true && J !== true) {
                var K = this;
                var I = $.dialog.confirm('<div id="maincontent" style="position:absolute;"><img style="margin:10px 10px 10px 10px;width:68px;height:68px;" src="http://static.tieba.baidu.com/tb/editor/v2/picasso/alarm.gif" /><div id="tipscontent" style="position:absolute;left:100px;top:15px;width:270px;font-size:14px;font-family:宋体"><b>您正在编辑涂鸦，现在退出将不会保存，您确定要退出？</b></div></div>', {title: "涂鸦编辑器",acceptValue: "确定",cancelValue: "取消"});
                I.width(420);
                I.height(90);
                I.bind("onaccept", function() {
                    TED.Editor.Status.isPicassoOpen = false;
                    K.isOpen = false;
                    K.content.innerHTML = "";
                    K.holder.style.display = "none";
                    if (K.currentOpen) {
                        K.currentOpen.className = K.currentOpen.className.replace(" open", "");
                        K.currentOpen = null
                    }
                    K.fireEvent("close")
                })
            } else {
                if (J == true) {
                    TED.Editor.Status.isPicassoOpen = false
                }
                this.isOpen = false;
                this.content.innerHTML = "";
                this.holder.style.display = "none";
                if (this.currentOpen) {
                    this.currentOpen.className = this.currentOpen.className.replace(" open", "");
                    this.currentOpen = null
                }
                this.fireEvent("close")
            }
        },toggle: function(N, M, L, I, O, J, K) {
            if (this.currentOpen && this.currentOpen === K) {
                this.close()
            } else {
                K.className = K.className + " open";
                this.currentOpen = K;
                this.open(N, M, L, I, O, J)
            }
        }});
    window.TED["augmentObject"] = augmentObject;
    function augmentObject(K, J) {
        for (var I in J) {
            if (J.hasOwnProperty(I)) {
                K[I] = K[I] !== undefined ? K[I] : J[I]
            }
        }
    }
    var SimpleAjax = {get: function(J, L, I) {
            var K = this.getXHR();
            K.open("GET", J, true);
            K.setRequestHeader("cache", false);
            K.onreadystatechange = function() {
                if (K.readyState !== 4) {
                    return
                }
                if (K.status == 200) {
                    if (typeof L === "function") {
                        L(K.responseText)
                    }
                } else {
                    if (typeof I === "function") {
                        I(K.statusText)
                    }
                }
                K = null
            };
            K.send(null)
        },getXHR: (function() {
            if (window.XMLHttpRequest) {
                return function() {
                    return new window.XMLHttpRequest()
                }
            } else {
                if (window.ActiveXObject) {
                    return function() {
                        return new window.ActiveXObject("Microsoft.XMLHTTP")
                    }
                } else {
                    throw "您的浏览器不支持AJAX!"
                }
            }
        })()};
    window.TED["SimpleAjax"] = SimpleAjax;
    var Storage = (function() {
        var K = "tieba";
        function O(P) {
            return P.replace(/[_\s]/g, function(Q) {
                return Q == "_" ? "__" : "_s"
            })
        }
        function L() {
            return document.getElementById(K + "-storage")
        }
        function N(P) {
            return {}.toString.call(P) === "[object Date]" && P.toString() !== "Invalid Date" && !isNaN(P)
        }
        function J() {
            var P;
            if (window.localStorage) {
                P = M()
            } else {
                if (window.ActiveXObject) {
                    P = I()
                }
            }
            return P
        }
        function I() {
            var P = document.createElement("div");
            P.style.display = "none";
            P.id = K + "-storage";
            document.body.appendChild(P);
            L().addBehavior("#default#userData");
            return {set: function(R, T, Q) {
                    var S = L(), W = O(R), V = Q && Q.expires ? Q.expires : new Date().getTime() + 365 * 24 * 60 * 60 * 1000;
                    N(V) && (V = V.getTime());
                    S.expires = new Date(V).toUTCString();
                    try {
                        S.setAttribute(W, T);
                        S.save(W)
                    } catch (U) {
                        throw "baidu.data.storage.set error! Maybe space overflow."
                    }
                    S = null
                },get: function(Q) {
                    var R = L(), U = O(Q), T = null;
                    try {
                        R.load(U);
                        T = R.getAttribute(U);
                        return T
                    } catch (S) {
                        throw S.message
                    }
                },del: function(Q) {
                    var R = L(), U = O(Q), T;
                    try {
                        R.load(U);
                        T = R.getAttribute(U);
                        if (T) {
                            R.removeAttribute(U);
                            R.expires = new Date(315532799000).toUTCString();
                            R.save(U);
                            return true
                        } else {
                            return false
                        }
                    } catch (S) {
                        return false
                    }
                }}
        }
        function M() {
            return {set: function(Q, R, P) {
                    var V = window.localStorage, U = O(Q), T = P && P.expires ? P.expires : 0;
                    N(T) && (T = T.getTime());
                    try {
                        V.setItem(U, T + "|" + R)
                    } catch (S) {
                        throw "baidu.data.storage.set error! Maybe space overflow."
                    }
                },get: function(Q) {
                    var V = window.localStorage, U = O(Q), T = null, P, S;
                    try {
                        T = V.getItem(U)
                    } catch (R) {
                        return null
                    }
                    if (T) {
                        P = T.indexOf("|");
                        S = parseInt(T.substring(0, P), 10);
                        if (new Date(S).getTime() > new Date().getTime() || S == 0) {
                            T = T.substring(P + 1, T.length);
                            return T
                        } else {
                            T = null;
                            this.del(Q);
                            return null
                        }
                    } else {
                        return null
                    }
                },del: function(P) {
                    var T = window.localStorage, S = O(P), R = null;
                    try {
                        R = T.getItem(S)
                    } catch (Q) {
                        return false
                    }
                    if (R) {
                        R = R.substring(R.indexOf("|") + 1, R.length);
                        R && T.removeItem(S);
                        return true
                    } else {
                        return false
                    }
                }}
        }
        return {
			set: function(Q, S, T, P) {
                var R = this;
                !R._storage && (R._storage = J());
                R._storage.set.apply(R._storage, arguments)
            },get: function(P) {
                var Q = this;
                !Q._storage && (Q._storage = J());
                return Q._storage.get.apply(Q._storage, arguments)
            },remove: function(P, R) {
                var Q = this;
                !Q._storage && (Q._storage = J());
                return Q._storage.del.apply(Q._storage, arguments)
            },isSupport: function() {
                return !!(window.localStorage || window.ActiveXObject)
            }
		}
    })();
    window.TED["Storage"] = Storage;
})();